<template>
  <div class="loginbBody">
    <div class="loginDiv">
      <div class="login-content">
        <h1 class="login-title">用户登录</h1>
        <el-form :model="loginForm" label-width="100px" :rules="rules" ref="loginForm">
          <el-form-item label="账号" prop="userName">
            <el-input
              style="width: 200px"
              type="text"
              v-model="loginForm.userName"
              autocomplete="off"
              size="small"
            ></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input
              style="width: 200px"
              type="password"
              v-model="loginForm.password"
              show-password
              autocomplete="off"
              size="small"
            ></el-input>
          </el-form-item>
          <el-form-item>
            <el-button class="butt" type="primary" @click="confirm">确 定</el-button>
          </el-form-item>
        </el-form>
        <div class="go-text" @click="goRegister">很尴尬没有账号，去注册</div>
      </div>
    </div>
  </div>
</template>

<script>
import { login } from "../http/axios";
// import { apiPost } from '../http/axios'
// import request from "../Api/request";

export default {
  name: "login",
  data() {
    return {
      loginForm: {
        userName: "",
        password: "",
      },
      rules: {},
    };
  },
  methods: {
    async confirm() {
      let body = {
        username: this.loginForm.userName,
        password: this.loginForm.password,
      };
      // console.log(login(body))
      login(body).then((res) => {
        console.log(res, "登录成功");
        if(res.obj.data[0].author===1){
          this.$router.push("/admin");
        }else{
          this.$router.push("/index");
        }
        
        localStorage.setItem("username", this.loginForm.userName);
      });

      //  await request.post(`/register?userName=${this.loginForm.userName}?password${this.loginForm.password}`)
      // alert("登录成功！")
      // this.$router.replace("/index/home");
    },
    goRegister() {
      this.$router.replace("register");
    },
  },
};
</script>

<style scoped>
.loginbBody {
  width: 100%;
  height: 100%;
  background-color: #b3c0d1;
}
.loginDiv {
  position: absolute;
  top: 50%;
  left: 50%;
  margin-top: -200px;
  margin-left: -250px;
  width: 450px;
  height: 330px;
  background: #fff;
  border-radius: 5%;
}
.login-title {
  margin: 20px 0;
  text-align: center;
}
.login-content {
  width: 400px;
  height: 250px;
  position: absolute;
  top: 25px;
  left: 25px;
}
.butt {
  margin-left: 60px;
}
/* .element.style {
    display: flex;
    justify-content: center;
  } */
.go-text {
  text-align: center;
  font-size: 13px;
  margin-top: 50px;
  cursor: pointer;
  text-decoration: underline;
}
</style>
